package com.maserb.monitor.entity;

import com.alibaba.fastjson.annotation.JSONField;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 *菜单权限表
 * @author  jimmy
 */
@Entity
@Table(name = "t_s_function")
@org.hibernate.annotations.Proxy(lazy = false)
public class Function extends BaseEntity implements java.io.Serializable {
	@JSONField(serialize=false)
	private Function TSFunction;//父菜单
	private String functionName;//菜单名称
	private Short functionLevel;//菜单等级
	private String functionUrl;//菜单地址
	private Short functionIframe;//菜单地址打开方式
	private String functionOrder;//菜单排序
	private Short functionType;//菜单类型
	private String functionIconStyle;//菜单图标样式
	private String functionNav;

	public boolean hasSubFunction(Map<Integer, List<Function>> map) {
		if(map.containsKey(this.getFunctionLevel()+1)){
			return hasSubFunction(map.get(this.getFunctionLevel()+1));
		}
		return false;
	}

	public boolean hasSubFunction(List<Function> functions) {
		for (Function f : functions) {
			if(f.getTSFunction()!=null){
				if(f.getTSFunction().getId().equals(this.getId())){
					return true;
				}
			}
			
		}
		return false;
	}

	private List<Function> TSFunctions = new ArrayList<Function>();

    @ManyToOne(fetch = FetchType.EAGER)
	@JoinColumn(name = "parentfunctionid")
	public Function getTSFunction() {
		return this.TSFunction;
	}

	public void setTSFunction(Function TSFunction) {
		this.TSFunction = TSFunction;
	}

	@Column(name = "functionname", nullable = false, length = 50)
	public String getFunctionName() {
		return this.functionName;
	}

	public void setFunctionName(String functionName) {
		this.functionName = functionName;
	}

	@Column(name = "functionlevel")
	public Short getFunctionLevel() {
		return this.functionLevel;
	}

	public void setFunctionLevel(Short functionLevel) {
		this.functionLevel = functionLevel;
	}
	
	@Column(name = "functiontype")
	public Short getFunctionType() {
		return this.functionType;
	}

	public void setFunctionType(Short functionType) {
		this.functionType = functionType;
	}
	
	@Column(name = "functionurl", length = 100)
	public String getFunctionUrl() {
		return this.functionUrl;
	}

	public void setFunctionUrl(String functionUrl) {
		this.functionUrl = functionUrl;
	}
	@Column(name = "functionorder")
	public String getFunctionOrder() {
		return functionOrder;
	}

	public void setFunctionOrder(String functionOrder) {
		this.functionOrder = functionOrder;
	}
	@JSONField(serialize=false)
	@OneToMany(cascade = CascadeType.ALL, fetch = FetchType.LAZY, mappedBy = "TSFunction")
	public List<Function> getTSFunctions() {
		return TSFunctions;
	}
	public void setTSFunctions(List<Function> TSFunctions) {
		this.TSFunctions = TSFunctions;
	}
	@Column(name = "functioniframe")
	public Short getFunctionIframe() {
		return functionIframe;
	}
	public void setFunctionIframe(Short functionIframe) {
		this.functionIframe = functionIframe;
	}

	@Column(name = "function_icon_style")
	public String getFunctionIconStyle() {
		return functionIconStyle;
	}

	public void setFunctionIconStyle(String functionIconStyle) {
		this.functionIconStyle = functionIconStyle;
	}

    @Column(name = "function_nav")
    public String getFunctionNav() {
        return functionNav;
    }

    public void setFunctionNav(String functionNav) {
        this.functionNav = functionNav;
    }
}